﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cinemon;
using System.Data;
using MySql.Data.MySqlClient;
using Cinemon.MySqlConnect;

public partial class Staff_Add : BaseClass
{
    protected void Page_Load(object sender, EventArgs e)
    {
		if (Session.SessionID != null && (!IsPostBack)) {
			LoadPositions();
		} 
    }

	protected void LoadPositions() {
		using (DatabaseManager manager = new DatabaseManager()) {
			ddlPosition.DataSource = manager.ExecuteQuery("GetAllRoles");
			ddlPosition.DataTextField = "Name";
			ddlPosition.DataValueField = "Id";
			ddlPosition.DataBind();
		}
	}
	protected void addUsers_Click(object sender, EventArgs e) {
		if (string.IsNullOrEmpty(txtHireDate.Text) || string.IsNullOrEmpty(txtName.Text)
			|| string.IsNullOrEmpty(txtSurname.Text)) {
			return;
		}

		using (DatabaseManager manager = new DatabaseManager()) {
			List<MySqlParameter> param = new List<MySqlParameter> {
				new MySqlParameter("staff_name", txtName.Text),
				new MySqlParameter("staff_surname", txtSurname.Text),
				new MySqlParameter("hire_date", DateTime.Parse(txtHireDate.Text)),
				new MySqlParameter("role_id",ddlPosition.SelectedItem.Value)
			};

			manager.ExecuteNonQuery("InsertStaff", param);
		}

		Response.Redirect("View.aspx");
	}
}